﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using Project.Engine.Utilities;
using Project.Module.DAO.BL;
using Project.Engine.Control;
using Project.Module.Model;

namespace Project.Module.View
{
    public class RightView : BasePageRazor
    {
        public string displayuser = String.Empty;
        public List<ProductModel> productNew = null;
        private int CustomerId = 0;
        protected int TotalCart = 0;
        private int MaxProductNew = DefineUtil.MaxProductNew;
        
        CustomerBL customerBl = new CustomerBL();
        CartBL cartBl = new CartBL();
        ProductBL productBl = new ProductBL();
        EventBL eventBl = new EventBL();

        protected override void InitializePage()
        {
            base.InitializePage();
            if (Session["username"] != null && ((string)(Session["username"])).Length > 0)
            {
                this.displayuser = (string)(Session["username"]) + " có ";
                this.CustomerId = customerBl.GetIdByUsername((string)(Session["username"]));
                this.TotalCart = cartBl.GetNumberCartByCustomerId(this.CustomerId);
            }

            GetListProductNew();           
        }

        private void GetListProductNew(){
            this.productNew = productBl.GetListProductNew(MaxProductNew);
            if (this.productNew != null)
            {
                foreach (var item in this.productNew)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                    item.CateName = ConvertUtil.GetCateNameUrlByCateId(item.CatagoryId);
                }
            }
        }
    }
}
